<template>
  <view class="password-card">
    <view class="card-content">
      <!-- 标题部分 -->
      <view class="title-section">
        <text class="title">{{ title }}</text>
      </view>

      <!-- 账号部分 -->
      <view class="info-section">
        <text class="label">账号：</text>
        <text class="value">{{ account }}</text>
        <view class="copy-icon" @tap="handleCopy(account)">
          <image src="/static/svg/copy.svg" mode="aspectFit" class="svg-icon" />
        </view>
      </view>

      <!-- 密码部分 -->
      <view class="info-section">
        <text class="label">密码：</text>
        <text class="value">{{ showPassword ? password : "******" }}</text>
        <view class="eye-icon" @tap="togglePassword">
          <image
            :src="
              showPassword
                ? '/static/svg/eye-open.svg'
                : '/static/svg/eye-close.svg'
            "
            mode="aspectFit"
            class="svg-icon"
          />
        </view>
        <view class="copy-icon" @tap="handleCopy(password)">
          <image src="/static/svg/copy.svg" mode="aspectFit" class="svg-icon" />
        </view>
      </view>

      <!-- 操作按钮 -->
      <view class="action-section">
        <view class="action-button delete" @tap="handleDelete">
          <image
            src="/static/svg/delete.svg"
            mode="aspectFit"
            class="svg-icon"
          />
          <text>删除</text>
        </view>
        <view class="action-button edit" @tap="handleEdit">
          <image src="/static/svg/edit.svg" mode="aspectFit" class="svg-icon" />
          <text>修改</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: "PasswordCard",
  props: {
    title: {
      type: String,
      required: true,
    },
    account: {
      type: String,
      required: true,
    },
    password: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      showPassword: false,
    };
  },
  methods: {
    togglePassword() {
      this.showPassword = !this.showPassword;
    },
    handleDelete() {
      this.$emit("delete");
    },
    handleEdit() {
      this.$emit("edit");
    },
    handleCopy(content) {
      const appVersion = uni.getSystemInfoSync(); // 这实际上是获取的客户端的版本号，而非应用版本号
      console.log("客户端版本号:", appVersion);
      uni.setClipboardData({
        data: content,
        success: () => {
          uni.showToast({
            title: "复制成功",
            icon: "success",
            duration: 2000,
          });
        },
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.password-card {
  margin: 20rpx;
  background: #ffffff;
  border-radius: 16rpx;
  box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.08);
  overflow: hidden;

  .card-content {
    padding: 24rpx;
  }

  .title-section {
    margin-bottom: 20rpx;

    .title {
      font-size: 32rpx;
      font-weight: bold;
      color: #333333;
    }
  }

  .info-section {
    display: flex;
    align-items: center;
    margin-bottom: 16rpx;

    .label {
      font-size: 28rpx;
      color: #666666;
      width: 100rpx;
    }

    .value {
      flex: 1;
      font-size: 28rpx;
      color: #333333;
      margin-right: 16rpx;
    }

    .eye-icon,
    .copy-icon {
      width: 50rpx;
      height: 50rpx;
      padding: 10rpx;
      display: flex;
      align-items: center;
      justify-content: center;

      .svg-icon {
        width: 100%;
        height: 100%;
      }
    }

    .eye-icon .svg-icon {
      filter: invert(45%) sepia(12%) saturate(14%) hue-rotate(22deg)
        brightness(92%) contrast(87%);
    }

    .copy-icon .svg-icon {
      filter: invert(47%) sepia(98%) saturate(1723%) hue-rotate(190deg)
        brightness(99%) contrast(91%);
    }

    .copy-icon {
      cursor: pointer;
      transition: opacity 0.2s;

      &:active {
        opacity: 0.7;
      }
    }
  }

  .action-section {
    display: flex;
    justify-content: flex-end;
    margin-top: 24rpx;
    padding-top: 20rpx;
    border-top: 2rpx solid #f5f5f5;

    .action-button {
      display: flex;
      align-items: center;
      padding: 12rpx 24rpx;
      margin-left: 20rpx;
      border-radius: 8rpx;

      .svg-icon {
        width: 40rpx;
        height: 40rpx;
        margin-right: 8rpx;
      }

      text {
        font-size: 24rpx;
      }

      &.delete {
        background: #fff2f2;

        .svg-icon {
          filter: invert(39%) sepia(85%) saturate(2152%) hue-rotate(331deg)
            brightness(100%) contrast(100%);
        }

        text {
          color: #ff4d4f;
        }
      }

      &.edit {
        background: #f0f7ff;

        .svg-icon {
          filter: invert(47%) sepia(98%) saturate(1723%) hue-rotate(190deg)
            brightness(99%) contrast(91%);
        }

        text {
          color: #1890ff;
        }
      }
    }
  }
}
</style> 